package xyz.robinbingo.rbtask.common.mp;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * CustomMetaObjectHandler
 *
 * @author Robin
 * @date 2021/7/17 19:02
 **/
@Component
public class CustomMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入方法自动填充字段
     *
     * @param metaObject metaObject
     * @author Robin
     * @date 2021/7/17 19:02
     **/
    @Override
    public void insertFill(MetaObject metaObject) {
        // todo robin
        String userName = "insertName";

        this.setFieldValByName("createdBy", userName, metaObject);
        this.setFieldValByName("modifiedBy", userName, metaObject);
    }

    /**
     * 更新方法自动填充字段
     *
     * @param metaObject metaObject
     * @author Robin
     * @date 2021/7/17 19:02
     **/
    @Override
    public void updateFill(MetaObject metaObject) {
        // todo robin
        String userName = "updateName";

        this.setFieldValByName("modifiedBy", userName, metaObject);
    }
}